#pragma once
#include "IDelegate.hpp"

namespace Typhoon {
	template<class Object, class Value> class Delegate : public IDelegate<Value>
	{
	public:
		typedef void (Object::* Method)(Value value);

		Delegate(Object* object, Method method);
		~Delegate();

		void Invoke(Value value);
		bool Match(IDelegate<Value>* other);
		
	private:
		

		Object* object;
		Method method;
	};
}

template<class Object, class Value> Typhoon::Delegate<Object, Value>::Delegate(Object* object,  Method method) {
	this->object = object;
	this->method = method;
}

template<class Object, class Value> Typhoon::Delegate<Object, Value>::~Delegate() {
}

template<class Object, class Value> void Typhoon::Delegate<Object, Value>::Invoke(Value value) {
	(object->*method)(value);
}

template<class Object, class Value> bool Typhoon::Delegate<Object, Value>::Match(IDelegate<Value>* other) {
	Delegate<Object, Value>* otherTest = dynamic_cast<Delegate<Object, Value>*>(other);
	if (!otherTest) return false;
	return otherTest->object == this->object && otherTest->method == this->method;
}